package com.qianshu.dsjjys.controller;

import com.alibaba.fastjson.JSONArray;
import com.qianshu.dsjjys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * UserController
 *
 * @author shira 2019/04/28 15:45
 */
@Api(tags = {" 数据交互存储接口"})
@RestController
@RequestMapping(value = "/users")     // 通过这里配置使下面的映射都在/users下
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "数据提交")
    @ApiImplicitParam(name = "paramList", value = "json数组,包含用户名name，身份证号码idCard")
    @RequestMapping(value = "/add", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    public Map add(@RequestParam(name = "paramList") String paramList) {
        System.out.println(paramList);
        JSONArray array=JSONArray.parseArray(paramList);
        String result = userService.add(array);
        Map map=new HashMap();
        map.put("code",200);
        map.put("msg","操作成功!");
        map.put("flowNo",result);
        return map;
    }

    @ApiOperation(value = "数据运算结果下载")
    @GetMapping(value = "/down")
    public void downloads(String fileName, HttpServletResponse response) {
        System.out.println("66666");
        userService.downloadFiles(fileName, response);
    }
    @ApiOperation(value = "数据运算")
    @GetMapping("/cll")
    public Map cller(@RequestParam String projectId,@RequestParam String jobId,@RequestParam String version) throws IOException {
        String userss = userService.caller(projectId, jobId, version);
        Map map=new HashMap();
        map.put("code",200);
        map.put("msg",userss);
        return map;

    }
}



